﻿-- =============================================
-- Script Template
-- =============================================
CREATE PROCEDURE P_TrendChart_7X_HMFB  --七星号码分布图

AS

set nocount on
 
Create table #LotteryNumberList7X(id int identity(1,1),Isuse varchar(20),LotteryNumber varchar(100),
		A_0 int,A_1 int,A_2 int,A_3 int,A_4 int,A_5 int,A_6 int,A_7 int,A_8 int,A_9 int,
		C_0 int,C_1 int,C_2 int,C_3 int,C_4 int,C_5 int,C_6 int,C_7 int,C_8 int,C_9 int,
		W_0 int,W_1 int,W_2 int,W_3 int,W_4 int,W_5 int,W_6 int,W_7 int,W_8 int,W_9 int,
		Q_0 int,Q_1 int,Q_2 int,Q_3 int,Q_4 int,Q_5 int,Q_6 int,Q_7 int,Q_8 int,Q_9 int,
		B_0 int,B_1 int,B_2 int,B_3 int,B_4 int,B_5 int,B_6 int,B_7 int,B_8 int,B_9 int,
		S_0 int,S_1 int,S_2 int,S_3 int,S_4 int,S_5 int,S_6 int,S_7 int,S_8 int,S_9 int,
		G_0 int,G_1 int,G_2 int,G_3 int,G_4 int,G_5 int,G_6 int,G_7 int,G_8 int,G_9 int)

declare  @cur cursor 
declare  @Isuse varchar(20), @WinLotterNumber varchar(100), @id int 

declare	 @A_0 int,@A_1 int,@A_2 int,@A_3 int,@A_4 int,@A_5 int,@A_6 int,@A_7 int,@A_8 int,@A_9 int
declare  @C_0 int,@C_1 int,@C_2 int,@C_3 int,@C_4 int,@C_5 int,@C_6 int,@C_7 int,@C_8 int,@C_9 int
declare  @W_0 int,@W_1 int,@W_2 int,@W_3 int,@W_4 int,@W_5 int,@W_6 int,@W_7 int,@W_8 int,@W_9 int
declare  @Q_0 int,@Q_1 int,@Q_2 int,@Q_3 int,@Q_4 int,@Q_5 int,@Q_6 int,@Q_7 int,@Q_8 int,@Q_9 int
declare  @B_0 int,@B_1 int,@B_2 int,@B_3 int,@B_4 int,@B_5 int,@B_6 int,@B_7 int,@B_8 int,@B_9 int
DECLARE  @S_0 int,@S_1 int,@S_2 int,@S_3 int,@S_4 int,@S_5 int,@S_6 int,@S_7 int,@S_8 int,@S_9 int
DECLARE  @G_0 int,@G_1 int,@G_2 int,@G_3 int,@G_4 int,@G_5 int,@G_6 int,@G_7 int,@G_8 int,@G_9 int

DECLARE  @A int, @C int,@W int ,@Q int ,@B int,@S int,@G int


Create table #tb(id int,PlayNo varchar(20),WinLotteryNumber varchar(100))

insert into #tb select top 100 Id,PlayNo,WinLotteryNumber from pm_plays where WinLotteryNumber <> '' and LotteryID = 2  order by Id desc

set @cur = cursor FAST_FORWARD for select PlayNo,WinLotteryNumber from #tb order by id asc

open @cur

fetch next from @cur into @Isuse, @WinLotterNumber

while @@fetch_status=0
begin

set @G_0 = -1 set @G_1 = -1 set @G_2 = -1 set @G_3 = -1 set @G_4 = -1 set @G_5 = -1 set @G_6 = -1  set @G_7 = -1 set @G_8 = -1 set @G_9 = -1
set @S_0 = -1 set @S_1 = -1 set @S_2 = -1 set @S_3 = -1 set @S_4 = -1 set @S_5 = -1 set @S_6 = -1  set @S_7 = -1 set @S_8 = -1 set @S_9 = -1
set @B_0 = -1 set @B_1 = -1 set @B_2 = -1 set @B_3 = -1 set @B_4 = -1 set @B_5 = -1 set @B_6 = -1  set @B_7 = -1 set @B_8 = -1 set @B_9 = -1
set @Q_0 = -1 set @Q_1 = -1 set @Q_2 = -1 set @Q_3 = -1 set @Q_4 = -1 set @Q_5 = -1 set @Q_6 = -1  set @Q_7 = -1 set @Q_8 = -1 set @Q_9 = -1
set @W_0 = -1 set @W_1 = -1 set @W_2 = -1 set @W_3 = -1 set @W_4 = -1 set @W_5 = -1 set @W_6 = -1  set @W_7 = -1 set @W_8 = -1 set @W_9 = -1
set @C_0 = -1 set @C_1 = -1 set @C_2 = -1 set @C_3 = -1 set @C_4 = -1 set @C_5 = -1 set @C_6 = -1  set @C_7 = -1 set @C_8 = -1 set @C_9 = -1
set @A_0 = -1 set @A_1 = -1 set @A_2 = -1 set @A_3 = -1 set @A_4 = -1 set @A_5 = -1 set @A_6 = -1  set @A_7 = -1 set @A_8 = -1 set @A_9 = -1

SET @A = SUBSTRING(@WinLotterNumber,1,1)
SET @C = SUBSTRING(@WinLotterNumber,2,1)	
SET @W = SUBSTRING(@WinLotterNumber,3,1)
SET @Q = SUBSTRING(@WinLotterNumber,4,1)
set @B = Substring(@WinLotterNumber,5,1) 
set @S = Substring(@WinLotterNumber,6,1) 
set @G = Substring(@WinLotterNumber,7,1)
		
IF(@A = 0)
BEGIN
	SET @A_0 = 0
END
		
IF(@A = 1)
BEGIN
	SET @A_1 = 1
END
		
IF(@A = 2)
BEGIN
	SET @A_2 = 2
END
		
IF(@A = 3)
BEGIN		
	SET @A_3 = 3
END
		
IF(@A = 4)
BEGIN		
	SET @A_4 = 4
END
		
IF(@A = 5)
BEGIN
	SET @A_5 = 5
END
		
IF(@A = 6)
BEGIN
	SET @A_6 = 6
END
		
IF(@A = 7)
BEGIN
	SET @A_7 = 7
END
		
IF(@A = 8)
BEGIN
	SET @A_8 = 8
END
		
IF(@A = 9)
BEGIN		
	SET @A_9 = 9
END
		
IF(@C = 0)
BEGIN
	SET @C_0 = 0		
END
		
IF(@C = 1)
BEGIN
	SET @C_1 = 1
END
		
IF(@C = 2)
BEGIN		
	SET @C_2 = 2
END
		
IF(@C = 3)
BEGIN		
	SET @C_3 = 3
END
		
IF(@C = 4)
BEGIN
	SET @C_4 = 4
END
		
IF(@C = 5)
BEGIN
	SET @C_5 = 5
END
		
IF(@C = 6)
BEGIN
	SET @C_6 = 6
END
		
IF(@C = 7)
BEGIN
	SET @C_7 = 7
END
		
IF(@C = 8)
BEGIN
	SET @C_8 = 8
END
		
IF(@C = 9)
BEGIN
	SET @C_9 = 9
END
		
IF(@W = 0)
BEGIN
	SET @W_0 = 0
END
		
IF(@W = 1)
BEGIN
	SET @W_1 = 1
END
		
IF(@W = 2)
BEGIN
	SET @W_2 = 2
END
		
IF(@W = 3)
BEGIN
	SET @W_3 = 3
END
		
IF(@W = 4)
BEGIN
	SET @W_4 = 4
END
		
IF(@W = 5)
BEGIN
	SET @W_5 = 5
END
		
IF(@W = 6)
BEGIN
	SET @W_6 = 6
END
		
IF(@W = 7)
BEGIN
	SET @W_7 = 7
END
		
IF(@W = 8)
BEGIN		
	SET @W_8 = 8
END
		
IF(@W = 9)
BEGIN
	SET @W_9 = 9
END
		
IF(@Q = 0)
BEGIN
	SET @Q_0 = 0
END
		
IF(@Q = 1)
BEGIN		
	SET @Q_1 = 1
END

IF(@Q = 2)
BEGIN
	SET @Q_2 = 2
END		
		
IF(@Q = 3)
BEGIN		
	SET @Q_3 = 3
END
				
IF(@Q = 4)
BEGIN		
	SET @Q_4 = 4
END
		
IF(@Q = 5)
BEGIN		
	SET @Q_5 = 5
END
		
IF(@Q = 6)
BEGIN		
	SET @Q_6 = 6
END		
		
IF(@Q = 7)
BEGIN
	SET @Q_7 = 7
END
		
IF(@Q = 8)
BEGIN
	SET @Q_8 = 8
END
		
IF(@Q = 9)
BEGIN
	SET @Q_9 = 9
END
		
IF(@B =0)
BEGIN
	SET @B_0 =0
END
		
IF(@B =1)
BEGIN
	SET @B_1 =1
END
		
IF(@B =2)
BEGIN
	SET @B_2 =2
END
		
IF(@B =3)
BEGIN
	SET @B_3 =3
END

IF(@B =4)
BEGIN
	SET @B_4 =4
END
		
IF(@B =5)
BEGIN
	SET @B_5 =5
END
		
IF(@B =6)
BEGIN
	SET @B_6 =6
END
		
IF(@B =7)
BEGIN		
	SET @B_7 =7
END
		
IF(@B =8)
BEGIN
	SET @B_8 =8
END
		
IF(@B =9)
BEGIN
	SET @B_9 =9
END

if(@G = 0)
begin
	set @G_0 =0
end
	
if(@G = 1)
begin
	set @G_1 =1
 end
	
if(@G = 2)
begin
	set @G_2 =2
end
	
if(@G = 3)
begin
	set @G_3 =3
end
	
if(@G = 4)
begin
	set @G_4 =4
end
	
if(@G = 5)
begin
	set @G_5 =5
end
	
if(@G = 6)
begin
	set @G_6 =6
end    
	
if(@G = 7)
begin
	set @G_7 =7
end   
	
if(@G = 8)
begin
	set @G_8 =8
end   
	
if(@G = 9)
begin
	set @G_9 =9
end
	
if(@S = 0)
begin
	set @S_0 =0
end

if(@S = 1)
begin
	set @S_1 =1
end

if(@S = 2)
begin
	set @S_2 =2
end

if(@S = 3)
begin
	set @S_3 =3
end

if(@S = 4)
begin
	set @S_4 =4
end

if(@S = 5)
begin
	set @S_5 =5
end

if(@S = 6)
begin
	set @S_6 =6
end   
 
if(@S = 7)
begin
	set @S_7 =7
end   

if(@S = 8)
begin
	set @S_8 =8
end  
 
if(@S = 9)
begin
	set @S_9 =9
end

insert into #LotteryNumberList7X values (@Isuse, @WinLotterNumber,
		@A_0, @A_1,@A_2,@A_3,@A_4,@A_5,@A_6,@A_7,@A_8,@A_9,
		@C_0, @C_1,@C_2,@C_3,@C_4,@C_5,@C_6,@C_7,@C_8,@C_9,
		@W_0, @W_1,@W_2,@W_3,@W_4,@W_5,@W_6,@W_7,@W_8,@W_9,
		@Q_0, @Q_1,@Q_2,@Q_3,@Q_4,@Q_5,@Q_6,@Q_7,@Q_8,@Q_9,
		@B_0 ,@B_1,@B_2 ,@B_3 ,@B_4 ,@B_5,@B_6 ,@B_7 ,@B_8,@B_9,
		@S_0 ,@S_1,@S_2 ,@S_3,@S_4,@S_5 ,@S_6 ,@S_7 ,@S_8 ,@S_9 ,
		@G_0 ,@G_1 ,@G_2 ,@G_3 ,@G_4 ,@G_5 ,@G_6 ,@G_7 ,@G_8 ,@G_9 )
						 	 			
fetch next from @cur into @Isuse, @WinLotterNumber

end

close @cur

select * from #LotteryNumberList7X

GO